package controller.ur.note;

import java.io.IOException;
import java.util.LinkedHashMap;
import java.util.Map;

import javax.ejb.EJB;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

import model.dao.NoteDaoLocal;
import model.entity.Note;
import model.entity.Photo;

import com.google.gson.Gson;

/**
 * Servlet implementation class SNoteDelete
 */
public class SNoteDelete extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
	@EJB
	private NoteDaoLocal noteDao;
	
	private Logger log=Logger.getLogger(SNoteDelete.class);
	
    /**
     * @see HttpServlet#HttpServlet()
     */
    public SNoteDelete() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String noteId=(String)request.getParameter("id");
		Note note=noteDao.findById(Integer.parseInt(noteId));
		if(note!=null){
			noteDao.remove(note);
			log.info("Note deleted: "+note.toString());
		}
		response.setContentType("application/json");
		response.setCharacterEncoding("UTF-8");
	    response.getWriter().close();
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
